package javabasic.slipch.calendarseeker;
import java.util.Scanner;
import java.util.InputMismatchException;
import javabasic.slipch.calendarseeker.CalendarSeeker;

public final class Main {

	public static void main(String[] args) {
		Date date = input();
		System.out.print("\n"+
		date.getMonth()+ "\\" +
		date.getDay()+ "\\" +
		date.getYear()+  
		" is " + CalendarSeeker.getDayOfWeek( date ));
	}
	
	private static Date input() {
		int year = new InputInteger( "Enter year ", 1900, 2100).doInput();
		int month = new InputInteger( "Enter month ", 1, 12).doInput();
		int day = new InputInteger( "Enter day ", 1, Month.getMonth(year, month).getDaysCount()).doInput();
		return new Date ( year, month, day );
	}
	
	private static class InputInteger {
	
		InputInteger(String prompt, int min, int max) {
			MIN = min;
			MAX = max;
			PROMPT = prompt;
		}
		
		public int doInput() {
			int result = Integer.MIN_VALUE;
			do {
				System.out.print(PROMPT);
				System.out.print(" from " + MIN);
				System.out.print(" to " + MAX + " : ");
				
				try {
					result = inputReader.nextInt();
					if (checkValue(result)) {
						break;
					} else {
						onIncorectInput();
					}
				} catch (InputMismatchException e) {
					onIncorectInput();
					inputReader.next();
				}
			} while (true);
		
			return result;
		}
		
		private void onIncorectInput() {
			System.out.print( "\nError. Should be a number from: " + MIN + " to: " + MAX + "\n");
		}
		
		private boolean checkValue(int v) {
			return v >= MIN && v <= MAX;
		}
		
		Scanner inputReader = new Scanner(System.in);
		private final String PROMPT;
		private final int MIN;
		private final int MAX;
	}
}
